package com.controller;


import com.pojo.Fdy;
import com.service.FdyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/fdy")
public class FdyController {

    @Autowired
    private FdyService fdyService;

    // 查询全部
    @RequestMapping("allfdy")
    public String allfdy(Model model) {
        List<Fdy> list = fdyService.queryAllfdy();
        model.addAttribute("list", list);
        System.out.println("the: " + list);
        return "allfdy";
    }

    // 删除
    @RequestMapping("/del/{fid}")
    public String deletefid(@PathVariable("fid") int fid) {
        fdyService.deleteByfid(fid);
        return "redirect:/fdy/allfdy";
    }

    //添加
    @RequestMapping("/toAddfdy")
    public String toAddPaper() {
        return "addfdy";
    }

    @RequestMapping("/addfdy")
    public String addPaper(Fdy fdy) {
        System.out.println(fdy);
        fdyService.addfdy(fdy);
        return "redirect:/fdy/allfdy";
    }


    //修改
    @RequestMapping("/toUpdatefdy")
    public String toUpdatefdy(Model model, int fid) {
        Fdy fdy = fdyService.queryByfid(fid);
        System.out.println(fdy);
        model.addAttribute("fdy", fdy);
        return "updatefdy";
    }

    @RequestMapping("/updatefdy")
    public String updatefdy(Model model, Fdy fdy) {
        System.out.println(" update: " + fdy);
        fdyService.updatefdy(fdy);
        fdy = fdyService.queryByfid(fdy.getFid());
        System.out.println(" update: " + fdy);
        return "redirect:/fdy/allfdy";
    }



}
